﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Oracle.DataAccess.Client;
using System.Xml;
using System.IO;
using System.IO.IsolatedStorage;

namespace TP2
{
    public partial class ConnectForm : Form
    {
        
        public ConnectForm()
        {
            InitializeComponent();
            
           
        }

        private void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
        {

        }

         
        private void buttonOk_Click(object sender, EventArgs e)
        {                        
            try
            {              
                ClassConnection conOb = new ClassConnection();
                string name = textBoxName.Text;
                string pass = maskedTextBoxPassword.Text;
                string ds = textBoxDb.Text;
                bool flag;
                if (checkBoxSave.Checked) { flag = true; } else { flag = false; }
                conOb.WriteSettings(name, pass, ds, flag);
                OracleConnection connection;
                ClassConnection conClass = new ClassConnection();
                connection = conClass.GetConnection();
                MainForm mainFr = new MainForm(this);
                mainFr.Enabled = true;
                mainFr.Visible = true;
                this.Visible = false;
                this.Enabled = false;
                conClass.CloseConnection(connection);
            }
            catch(OracleException) { MessageBox.Show("подключится не удалось! проверьте параметры подключения!"); } 
            
        }

        

        private void ConnectForm_Load(object sender, EventArgs e)
        {
            try
            {
                string[] mas_setting = new string[4];
                ClassConnection conOb = new ClassConnection();
                mas_setting[0] = "";
                mas_setting[1] = "";
                mas_setting[2] = "";
                mas_setting[3] = "";
                mas_setting = conOb.GetSettings();
                if (mas_setting[3].Equals("true"))
                {
                    textBoxName.Text = mas_setting[0];
                    textBoxDb.Text = mas_setting[2];
                    maskedTextBoxPassword.Text = mas_setting[1];
                    checkBoxSave.Checked = true;
                }
            }
            catch (Exception)
            {
                textBoxName.Text = "";
                textBoxDb.Text = "";
                maskedTextBoxPassword.Text = "";
                checkBoxSave.Checked = false;
            }
        }
    }
}
